package demo;

import api.GreetingService;
import api.po.Pojo;
import api.result.Result;
import org.apache.dubbo.common.json.JSON;
import org.apache.dubbo.rpc.RpcContext;

import java.io.IOException;

/**
 * Copyright (c)  by www.leya920.com
 * All right reserved.
 * Create Date: 2020-11-21 15:39
 * Create Author: xuweiwei
 * File Name: GreetingServiceImpl.java
 * Last version:  1.0
 * Function: //TODO
 * Last Update Date: 2020-11-21 15:39
 * Last Update Log:
 * Comment: //TODO
 **/
public class GreetingServiceImpl implements GreetingService {
    @Override
    public String sayHello(String name) {

        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        return "hello " + name + " " + RpcContext.getContext().getAttachment("company");

    }

    @Override
    public Result<String> testGeneric(Pojo pojo) {

        Result<String> result = new Result<>();

        result.setSuccess(true);
        try {
            result.setData(JSON.json(pojo));
        } catch (IOException e) {
            e.printStackTrace();
        }

        return result;
    }
}
